package com.coolbi.security.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.security.dao.UserToGroupDao;
import com.coolbi.security.entity.User;
import com.coolbi.security.entity.UserGroup;
import com.coolbi.security.entity.UserToGroup;
import com.coolbi.security.mapper.UserToGroupMapper;

public class UserToGroupDaoImpl implements UserToGroupDao {

	@Autowired
	private UserToGroupMapper userToGroupMapper;
	public void setUserToGroupMapper(UserToGroupMapper userToGroupMapper) {
		this.userToGroupMapper = userToGroupMapper;
	}

	@Override
	public List<UserGroup> findGroupByUserId(long id) {
		return userToGroupMapper.findGroupByUserId(id);
	}

	@Override
	public List<UserToGroup> find(Map<String, Object> parameter) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<UserToGroup> find(Map<String, Object> parameter, int offset,
			int limit) {
		return userToGroupMapper.listByParameterPage(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return userToGroupMapper.countByParameter(parameter);
	}

	@Override
	public List<UserToGroup> search(String keyword, int offset, int limit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int countByKeyword(String keyword) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public UserToGroup save(UserToGroup obj) {
		userToGroupMapper.save(obj);
		return obj;
	}

	@Override
	public int update(UserToGroup obj) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int delete(long id) {
		return userToGroupMapper.delete(id);
	}

	@Override
	public UserToGroup get(long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<UserToGroup> list() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<UserToGroup> list(int offset, int limit) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int count() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int deleteByGroupId(long id) {
		return userToGroupMapper.deleteByGroupId(id);
	}

	@Override
	public List<User> findUserByGroupId(Map<String, Object> parameter, int offset, int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return userToGroupMapper.findUserByGroupId(parameter);
	}

	@Override
	public int saveByBatch(Long userId, List<Long> groupIds) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("userId", userId);
		parameter.put("groupIds", groupIds);
		return userToGroupMapper.saveByBatch(parameter);
	}
}
